/* eslint-disable */
import axios from "axios";
import { VueAxios } from "./axios"; // 自己封装的axois相关函数
import { setToken } from "../api/token.js";
import { myData } from "../storage.js";
import vueBus from "../bus.js";
import { ACCESS_TOKEN } from "../api/dToken.js";
// 创建 axios 实例
// const apiUrl = "http://192.168.2.114:8082/api";
const apiUrl = "http://gitlab.companiontek.com:8087/mock/21/api/";
// const apiUrl = "http://106.75.129.117:8082";
const service = axios.create({
  baseURL: apiUrl, // 地址
  withCredentials: true,
  // timeout: 6000
});
// 箭头函数，参数为error
const err = error => {
  vueBus.$emit("loading", "err")
};
// 发送请求拦截
service.interceptors.request.use(config => {
  const token = myData(ACCESS_TOKEN)[0];
  if (token)
    config.headers["Access-Token"] = token; // 让每个请求携带自定义 token 请根据实际情况自行修改
  return config;
}, err);

// 获取结果拦截
service.interceptors.response.use(response => {
  setToken(response)
  return response.data;
}, err);

const installer = {
  vm: {},
  install(Vue) {
    Vue.use(VueAxios, service);
  }
};

export { installer as VueAxios, service as axios, apiUrl as url };
/* eslint-disable */